<template>
  <div  v-if="setresult" class="inputs">
    <div class="fen" style="cursor: pointer;" @click="score">查看得分</div>
    <div v-show="isSubmit">
      <el-row :gutter="50">
        <el-col :span="6">
          <label>评分总和</label>
          <el-input disabled v-model="setresult.resultValue"></el-input>
        </el-col>
        <el-col :span="6" v-show="setId">
          <label>判定等级 </label>
          <el-select v-model="setresult.rId" placeholder="请选择判定等级" :disabled = "isDisabled">
            <el-option
              v-for="item in careJudgment"
              :label="item.resultName"
              :value="item.rid">
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="6" v-show="!setId">
          <label>照护等级 </label>
          <el-select v-model="setresult.careLevel" placeholder="请选择照护等级"  :disabled = "isDisabled">
            <el-option
              v-for="item in careLevelOptions"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row :gutter="50">
        <el-col :span="6">
          <label>评估人员</label>
          <el-input v-model="setresult.auditUser" placeholder="请输入内容"  :disabled = "isDisabled"></el-input>
        </el-col>
        <el-col :span="6">
          <label>评估时间</label>
          <el-date-picker
            v-model="setresult.auditTime"
            type="date"
            placeholder="选择日期" :disabled = "isDisabled">
          </el-date-picker>
        </el-col>
      </el-row>
      <el-row :gutter="50">
        <el-col :span="6">
          <label>结论备注</label>
          <el-input
            placeholder="请输入结论备注"
            :disabled = "isDisabled"
            v-model="setresult.comment">
          </el-input>
        </el-col>
        <el-col :span="6 "  v-show="!setId">
          <label>评估结论</label>
          <el-input
            type="text"
            autosize
            placeholder="请输入评估结论"
            disabled v-model="setresult.resultName">
          </el-input>
        </el-col>
      </el-row>
      <div>
         <!--
        <el-button size="small" type="info" class="lightGreenBtn"  v-show="setId" @click="putResult" :disabled="isDisabled" >提交评估表</el-button>
         -->
        <el-button size="small" type="info" class="lightGreenBtn"  v-show="setId" @click="putResult">提交评估表</el-button>
      </div>
      <div>
        <el-button size="small" type="info" class="lightGreenBtn" v-show="!setId" @click="affirmResult" :disabled="isDisabled">确认评估结果</el-button>
      </div>
    </div>
  </div>
</template>

<script>
  import checkInApi from '../../../service/member/checkInApi';
  import commonApi from '../../../service/member/commonApi';
  import commonJs from '../../../config/common';
  export default {
    props: ["setresult", "results", "setId","member", "currentTasId", "careJudgment","careLevelOptions","optionsDisabled","optionsLength"],
    data(){
      return {
        isSubmit: false,
        isDisabled: false,
        data: {}
      }
    },
    methods: {
      init(){
        this.RESULTS = this.results;
        this.isDisabled = this.optionsDisabled;
//        this.consoleresults.itemResultVOList=this.results.itemResultVOList;
      },
      /**
       *获得评估分项得分
       */
      score(){
        let self = this;
        self.data.assessId = this.results.assessId;
        self.data.sheetId = this.results.sheetId;
        self.data = {itemResultQueryDTOList: []};
        for (var i = 0; i < this.results.itemResultVOList.length; i++) {
          if (this.results.itemResultVOList[i].setId == this.setId) {
            self.data.itemResultQueryDTOList.push(this.results.itemResultVOList[i]);
            self.data.setId = this.results.itemResultVOList[i].setId;
          }
        }

       /*if (self.setresult.rId != 0) {
          self.isSubmit = true;
          self.$emit("isSubmit", self.isSubmit);
          return true;
        }*/
        if (!self.setId) {
          self.isSubmit = true;
          self.$emit("isSubmit", self.isSubmit);
          return true;
        }

//        if (self.data.itemResultQueryDTOList == null || self.data.itemResultQueryDTOList.length == 0 ||self.data.itemResultQueryDTOList.length != self.optionsLength) {
//          self.isSubmit = false;
//          self.$emit("isSubmit", self.isSubmit);
////          this.$message.info('评估结果不能全部为空!');
//          this.$message({
//            message: '评估项目全部必填!',
//            type: 'warning'
//          });
//          return false;
//        }
        if (self.data.itemResultQueryDTOList == null || self.data.itemResultQueryDTOList.length == 0) {
          self.isSubmit = false;
          self.$emit("isSubmit", self.isSubmit);
          this.$message({
           message: '评估结果不能全部为空!',
           type: 'warning'
          });
          return false;
        }

        checkInApi.getScore(self.data).then(function (response) {
          self.results.resultValue = response.body.data.resultValue;
          self.setresult.resultValue = response.body.data.resultValue;
         // self.setresult.auditUser=response.body.data.createUser;
          //self.results.auditUser = response.body.data.createUser;
          if(self.setresult.auditUser==""){
            self.setresult.auditUser=response.body.data.auditUser;
          }
          if(self.setresult.auditTime==""){
            self.setresult.auditTime=response.body.data.auditTime;
          }
          if(self.setresult.resultName==""){
            self.setresult.resultName=response.body.data.resultName;
          }
          self.results.rId = response.body.data.rId;
          self.setresult.rId = response.body.data.rId;
          self.isSubmit = true;
          self.$emit("isSubmit", self.isSubmit);
        });
      },
      /**
       *提交评估结果
       */
      putResult(){
        let self = this;
        self.data.comment = this.setresult.comment;
        self.data.auditUser = this.setresult.auditUser;
        self.data.auditTime = this.setresult.auditTime;
        self.data.rId = this.setresult.rId;
        self.data.assessId = this.results.assessId;
        self.data.sheetId = this.results.sheetId;
        checkInApi.putResult(self.data).then(function (response) {
          //每项结果提交成功TODO
          self.isDisabled = true;
        });
      },
      /**
       *确认最终评估结果
       */
      affirmResult(){
        let self = this;
        self.data.comment = this.setresult.comment;
        self.data.auditUser = this.setresult.auditUser;
        self.data.auditTime = commonJs.formatDate(this.setresult.auditTime);
        self.data.rId = this.setresult.rId;
        self.data.assessId = this.setresult.assessId;
        self.data.sheetId = this.setresult.sheetId;
        self.data.memberId = this.member.memberId;
        self.data.runId = this.member.runId;
        self.data.tasId = this.currentTasId;
        self.data.careLevel = this.setresult.careLevel;
        self.data.itemResultQueryDTOList = this.results.itemResultVOList;
        self.data.sheetType=this.setresult.sheetType;
       //console.log(this.results.itemResultVOList);
//        for (var i = 0; i < this.results.itemResultVOList.length; i++) {
//          if (this.results.itemResultVOList[i].setId == this.setId) {
//            self.data.itemResultQueryDTOList.push(this.results.itemResultVOList[i]);
//          }
//        }
//        console.log(self.data);

        checkInApi.affirmResult(this.member.actId,self.data).then(function () {
          self.$message.info('评估完成!');
          self.$emit("goto","inApply_servicePlan");
        });

      }
    },
    mounted: function () {
      this.init();
      console.log(this.setresult);
    }
  }
</script>

<style>


</style>
